<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- public quote -->
<%@include file="/jsp/comm_css_include.jsp"%>
<!-- jqgrid-->
<link href="${basePath}/css/plugins/jqgriddemo/css/ui.jqgrid-bootstrap.min.css" rel="stylesheet" />
<!doctype html>
<html>

<body class="gray-bg">
	<div class="wrapper wrapper-content animated fadeInRight">
		<div class="iboxtitle">
			<span><i class="glyphicon glyphicon-map-marker"></i>&nbsp;贷中业务>风控资料登记</span>
			<a href="javascript:void(0)"></a>
		</div>
		<div class="buttonfixed">
			<button class="btn dpbtn_blue" id="save" type="button" onclick="saveOrUpdate();">保存</button>
			<button class="btn dpbtn_blue" id="update" type="button" onclick="saveOrUpdate();">修改</button>
		</div>
		<%@include file="/jsp/comm_yw_info_include.jsp"%>
		<div class="business-manwife">风控信息录入</div>
		<input type="hidden" id="fkId" /> <input type="hidden" id="middleAuditStatus" />
		<form class="form-horizontal" id="commentForm">
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0" class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">开卡申请提交时间：</label></td>
						<td><input id="timeApplyOpencard"  name="timeApplyOpencard"  readonly="readonly" placeholder="开卡申请提交时间" class="form-control" /></td>
					</tr>
					<tr>
						<td align="right" class="inputText"><label class="control-label np">贷款合同收到时间：</label></td>
						<td class="inputValue"><input id="timeReceiveContract" readonly="readonly" onclick="laydate()" name="timeReceiveContract" required="required" placeholder="贷款合同收到时间(必填)" class="laydate-icon form-control" /></td>
						<td class="timeReceiveContractStatus" style="display: none;">&nbsp;&nbsp;&nbsp;
							<button class="dpbtn dpbtn_blue"  type="button" onclick="saveTime(this);">保存</button>&nbsp;
							<button class="dpbtn dpbtn_red" type="button" onclick="commitTime(this);">提交</button>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top"><label class="control-label np">合同收到备注：</label></td>
						<td colspan="3"><textarea id="remarkReceiveContract" rows="" cols="" class="form-control"></textarea></td>
					</tr>
					<tr>
						<td align="right" class="inputText"><label class="control-label np">贷款合同齐全时间：</label> </td>
						<td class="inputValue"><input id="timeContractFull"  readonly="readonly" onclick="laydate()" name="timeContractFull" required="required" placeholder="贷款合同齐全时间(必填)" class="laydate-icon form-control" /></td>
						<td class="timeContractFullStatus" style="display: none;">&nbsp;&nbsp;&nbsp;
							<button class="dpbtn dpbtn_blue"  type="button" onclick="saveTime(this);">保存</button>&nbsp;
							<button class="dpbtn dpbtn_red" type="button" onclick="commitTime(this);">提交</button>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top"><label class="control-label np">合同齐全备注：</label></td>
						<td colspan="3"><textarea id="remarkContractFull" rows="" cols="" class="form-control"></textarea></td>
					</tr>
					
					<tr>
						<td align="right" class="inputText"><label class="control-label np">合同移交机打时间：</label></td>
						<td class="inputValue"><input id="timeContractHandPrint"  onclick="laydate()" name="timeContractHandPrint" required="required" placeholder="合同移交机打时间(必填)" class="laydate-icon form-control" /></td>
						<td class="timeContractHandPrintStatus" style="display: none;">&nbsp;&nbsp;&nbsp;
							<button class="dpbtn dpbtn_blue"  type="button" onclick="saveTime(this);">保存</button>&nbsp;
							<button class="dpbtn dpbtn_red" type="button" onclick="commitTime(this);">提交</button>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top"><label
							class="control-label np">移交机打备注：</label></td>
						<td colspan="3"><textarea id="remarkContractHandPrint"
								name="" placeholder="" class="form-control"></textarea></td>
					</tr>
					<tr>
					<td align="right"><label class="control-label np">贷款合同机打时间：</label><img class="curpo" title="该字段在合同套打模块处理" src="${basePath}/img/ask.png" />
						</td>
						<td><input id="timeContractPrint" name="timeContractPrint"  readonly="readonly" placeholder="贷款合同机打时间" class="form-control" /></td>
						<td align="right"><label class="control-label np">贷款合同机打人员：</label><img class="curpo" title="该字段在合同套打模块处理" src="${basePath}/img/ask.png" /></td>
						<td><input id="operatorContractPrint" readonly="readonly" name="operatorContractPrint" placeholder="贷款合同机打人员" class="form-control" /></td>
					</tr>
					<tr>
						<td align="right" class="inputText"><label class="control-label np">合同送交银行时间：</label></td>
						<td class="inputValue"><input id="timeSendToBank" onclick="laydate()" readonly="readonly" name="timeSendToBank" required="required" placeholder="合同送交银行时间(必填)" class="laydate-icon form-control" /></td>
						<td colspan="2"><select id="timeSendToBank2" class="select-control floatLeft" disabled="disabled" style="width: 80px;">
								<option value="">请选</option> <option value="1">上午</option> <option value="2">下午</option> </select>
							<button class="dpbtn dpbtn_blue floatLeft timeSendToBankStatus" style="display: none;" type="button" onclick="saveTime(this);">保存</button>
							<button class="dpbtn dpbtn_red  floatLeft timeSendToBankStatus" style="display: none;" type="button" onclick="commitTime(this);">提交</button>
						</td>
					</tr>
					<tr>
						<td align="right" valign="top"><label
							class="control-label np">送交银行备注：</label></td>
						<td colspan="3"><textarea id="remarkContractPrint" name=""
								placeholder="" class="form-control"></textarea></td>
					</tr>
				</table>
			</div>
			<div class="business-manwife">经办信息</div>
			<div class="padding-nono">
				<table cellpadding="0" cellspacing="0" border="0"
					class="buyinfor-table">
					<tr>
						<td align="right"><label class="control-label np">经办人：</label>
						</td>
						<td><input id="jb_name" class="form-control"
							readonly="readonly" value="${current_user_key.uname}" /></td>
						<td align="right"><label class="control-label np">经办时间：</label>
						</td>
						<td><input id="jb_time" name="jb_time" onclick="laydate()"
							class="laydate-icon form-control" required="required"
							placeholder="经办时间(必填)" /></td>
					</tr>
				</table>
			</div>
		</form>
	</div>

	<!-- public quote -->
	<%@include file="/jsp/comm_js_include.jsp"%>

	<%@include file="/js/common-dpqc/dpqc-validate/comm_validate_include.jsp"%>
	<!-- jqGrid -->
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/jquery.jqGrid.min.js"></script>
	<script type="text/javascript" charset="utf-8" src="${basePath}/js/plugins/jqgriddemo/js/grid.locale-cn.min.js"></script>
	<!-- layerDate plugin javascript -->
	<script src="${basePath}/js/plugins/layer/laydate/laydate.js"></script>

	<script type="text/javascript">
	    jQuery(function($) { 
	    	$("#save").hide();
	    	$("#update").hide();
	    	getDataById();
	    });
	    var getDataById=function(){
	    	$.dpAjax({
	    		show:false,
	    		url:'${basePath}/DzLoanMiddleAuditController/getByBusiId',
	    		data:{"busiId":$.getUrlData("busiId")},
    			success: function(datas){
    				    layer.msg('执行成功！', {icon: 6});
	    				var record=datas.result;
	    				if(record){
	    					$("#save").hide();
	    					$("#update").show();
							$("#fkId").val(record.replaceId);
							$("#middleAuditStatus").val(record.middleAuditStatus);
							if(record.timeReceiveContractStatus == 20){
								$(".timeReceiveContractStatus").hide();
								$("#timeReceiveContract").attr("readonly","readonly");
								$("#timeReceiveContract").removeAttr("onclick");
								$("#remarkReceiveContract").attr("readonly","readonly");
							}else{
								$(".timeReceiveContractStatus").show();
								$("#timeReceiveContract").removeAttr("readonly");
								$("#remarkReceiveContract").removeAttr("readonly","readonly");
							}
							
							if(record.timeContractFullStatus == 20){
								$(".timeContractFullStatus").hide();
								$("#timeContractFull").attr("readonly","readonly");
								$("#timeContractFull").removeAttr("onclick");
								$("#remarkContractFull").attr("readonly","readonly");
							}else{
								$(".timeContractFullStatus").show();
								$("#timeContractFull").removeAttr("readonly");
								$("#remarkContractFull").removeAttr("readonly","readonly");
							}
							if(record.timeContractHandPrintStatus == 20){
								$(".timeContractHandPrintStatus").hide();
								$("#timeContractHandPrint").attr("readonly","readonly");
								$("#timeContractHandPrint").removeAttr("onclick");
								$('#remarkContractHandPrint').attr("readonly","readonly");
							}else{
								$(".timeContractHandPrintStatus").show();
								$("#timeContractHandPrint").removeAttr("readonly");
								$('#remarkContractHandPrint').removeAttr("readonly","readonly");
							}
							if(record.timeSendToBankStatus == 20){
								$(".timeSendToBankStatus").hide();
								$("#timeSendToBank").attr("readonly","readonly");
								$("#timeSendToBank2").attr("disabled");
								$("#timeSendToBank").removeAttr("onclick");
								$('#remarkContractPrint').attr("readonly","readonly");
							}else{
								$(".timeSendToBankStatus").show();
								$("#timeSendToBank").removeAttr("readonly");
								$("#timeSendToBank2").removeAttr("disabled");
								$('#remarkContractPrint').removeAttr("readonly","readonly");
							}
		    				$("#remarkReceiveContract").val(record.remarkReceiveContract);
		    			    $("#timeReceiveContract").val(formateToDate(record.timeReceiveContract,true));
		    			    $("#timeContractFull").val(formateToDate(record.timeContractFull,true));
		    			    $("#remarkContractPrint").val(record.remarkContractPrint);
		    			    $("#timeContractHandPrint").val(formateToDate(record.timeContractHandPrint,true));
		    			    $("#timeSendToBank").val(formateToDate(record.timeSendToBank,true));
		    			    $("#timeContractPrint").val(formateToDate(record.timeContractPrint,true));
		    			
		    		        $("#timeSendToBank2").val(record.timeSendToBank2);
		    			    $("#remarkContractHandPrint").val(record.remarkContractHandPrint);
		    			    $("#operatorContractPrint").val(record.operatorContractPrint);
		    			    $("#remarkContractFull").val(record.remarkContractFull);
		    			    $("#timeApplyOpencard").val(formateToDate(record.timeApplyOpencard,true));
		    			    /* $("#timeApplyOpencard").attr("readonly","readonly"); */
		    			    $("#timeApplyOpencard").removeAttr("onclick");
		    			    $("#jb_time").val(formateToDate(record.jbDate,true))
	    				} else {
	    					 $("#save").show();
	    					 $("#update").hide();
	    					 $(".timeReceiveContractStatus").show();
							 $("#timeReceiveContract").removeAttr("readonly","readonly");
							 $("#timeReceiveContract").attr("onclick");
							 
							 $(".timeContractFullStatus").show();
							 $("#timeContractFull").removeAttr("readonly","readonly");
							 $("#timeContractFull").attr("onclick");
							 
							 $(".timeContractHandPrintStatus").show();
							 $("#timeContractHandPrint").removeAttr("readonly","readonly");
							 $("#timeContractHandPrint").attr("onclick");
							 
							 $(".timeSendToBankStatus").show();
							 $("#timeSendToBank").removeAttr("readonly","readonly");
							 $("#timeSendToBank2").removeAttr("disabled");
							 $("#timeSendToBank").attr("onclick");
							 
							 $("#remarkReceiveContract").removeAttr("readonly","readonly");
							 $("#remarkContractFull").removeAttr("readonly","readonly");
							 $('#remarkContractHandPrint').removeAttr("readonly","readonly");
							 $('#remarkContractPrint').removeAttr("readonly","readonly");
	    				}
                 }
	    	});
	    }
	    var saveOrUpdate = function(){
	    	var busiStatus=$.getUrlData("busiStatus");
	    	//备用，误删
// 	    	if(busiStatus!="" && busiStatus<400){
// 	    		layer.msg('已提车之后才能保存或修改或进行提交！', {icon: 5});
// 	    		return false;
// 	    	}
// 	    	var middleAuditStatus=$("#middleAuditStatus").val();
// 	    	if(middleAuditStatus!="" && middleAuditStatus==20){
// 	    		layer.msg('已提交过的数据不能再做修改操作！', {icon: 5});
// 	    		return false;
// 	    	}
	    	var data={};
	    	var fkId=$("#fkId").val();
	    	var url='${basePath}/DzLoanMiddleAuditController/insert';
	    	if(fkId && fkId != ""){
	    		data.id=fkId;
	    		url='${basePath}/DzLoanMiddleAuditController/modify';
	    	}else{
	    		data.jbDate=$("#jb_time").val();
		    	data.creatorName=$("#jb_name").val();
	        	data.creator="${current_user_key.id}";
	    	}
	    	data.busiId=$.getUrlData("busiId");
	    	data.remarkReceiveContract=$("#remarkReceiveContract").val();
	    	data.timeReceiveContract=$("#timeReceiveContract").val();
	    	data.timeContractFull=$("#timeContractFull").val();
	    	data.remarkContractPrint=$("#remarkContractPrint").val();
	    	data.timeContractHandPrint=$("#timeContractHandPrint").val();
	    	data.timeSendToBank=$("#timeSendToBank").val();
	    	data.timeContractPrint=$("#timeContractPrint").val();
	    	data.timeSendToBank2=$('#timeSendToBank2 option:selected') .val();
	    	data.remarkContractHandPrint=$("#remarkContractHandPrint").val();
	    	data.operatorContractPrint=$("#operatorContractPrint").val();
	    	data.remarkContractFull=$("#remarkContractFull").val();
	    	data.timeApplyOpencard=$("#timeApplyOpencard").val();
	    	data.middleAuditStatus=10;
        	data.busiId=$.getUrlData("busiId");
        	data.cusId=$.getUrlData("cusId");
	    	$.dpAjax({
	    		url:url,
	    		data:data,
    			success: function(datas){
					layer.msg('执行成功！', {icon: 6});
					$("#fkId").val(datas.result);
	    			window.location.href="dzLoanMiddleAuditList.jsp";
                 }
	    	});
	    }
	    
	    var saving = false;
	    var saveTime = function(obj){
	    	if(saving) {
	    		layer.tips('请不要过快连续点击',{tips: 5});
	    		return;
	    	}
	    	saving = true;
	    	var data={};
	    	data.id = $("#fkId").val();
	    	data.busiId=$.getUrlData("busiId");
	    	
			var timeCName = $(obj).parents('td').siblings('.inputText').children('label').text();
			var timeCValue = $(obj).parents('td').siblings('.inputValue').children('input').val();
			var idAttr = $(obj).parents('td').siblings('.inputValue').children('input').attr("id");
			//提交
	    	if("timeReceiveContract" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('贷款合同收到时间不能为空!',"#timeReceiveContract",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeReceiveContract = timeCValue;
	    		data.timeCName = timeCName;
	    		data.remarkReceiveContract = $('#remarkReceiveContract').val();
	    		
	    	} else if("timeContractFull" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('贷款合同齐全时间不能为空!',"#timeContractFull",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeContractFull = timeCValue;
	    		data.timeCName = timeCName;
	    		data.remarkContractFull = $('#remarkContractFull').val();
	    		
	    	}else if("timeContractHandPrint" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('合同移交机打时间不能为空!',"#timeContractHandPrint",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeContractHandPrint = timeCValue;
	    		data.timeCName = timeCName;
	    		data.remarkContractHandPrint = $('#remarkContractHandPrint').val();
	    		
	    	} else if("timeSendToBank" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('合同送交银行时间不能为空!',"#timeSendToBank",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		if($("#timeSendToBank2").val() == ""){
	    			layer.tips('请选择上下午!',"#timeSendToBank2",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeSendToBank = timeCValue;
	    		data.timeSendToBank2 = $("#timeSendToBank2").val();
	    		data.timeCName = timeCName;
	    		data.remarkContractPrint = $('#remarkContractPrint').val();
	    	}
			
	    	var url;
	    	var fkId = $('#fkId').val();
	    	if(fkId && fkId != ""){
	    		url='${basePath}/DzLoanMiddleAuditController/modifyTime';
	    	}else{
	    		url='${basePath}/DzLoanMiddleAuditController/saveTime';
	    	}
	    	
	    	$.dpAjax({
	    		data:data,
		    	url:url,
	   			success: function(datas){
	   				layer.msg('执行成功！', {icon: 6});
	   				$("#fkId").val(datas.result);
					return;
	   			},
	   			complete:function(){
	   				saving = false;
	   			}
	    	});
	    }
	   
	    var commitTime = function(obj){
	    	if(saving) {
	    		layer.tips('请不要过快连续点击',{tips: 5});
	    		return;
	    	}
	    	saving = true;
	    	var data={};
	    	data.id=$("#fkId").val(); 
	    	data.busiId=$.getUrlData("busiId");
	    	
			var timeCName = $(obj).parents('td').siblings('.inputText').children('label').text();
			var timeCValue = $(obj).parents('td').siblings('.inputValue').children('input').val();
			var idAttr = $(obj).parents('td').siblings('.inputValue').children('input').attr("id");
			//提交
	    	if("timeReceiveContract" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('贷款合同收到时间不能为空!',"#timeReceiveContract",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeReceiveContract = timeCValue;
	    		data.timeReceiveContractStatus = 20;
	    		data.timeCName = timeCName;
	    		data.remarkReceiveContract = $('#remarkReceiveContract').val();
	    		
	    		$("#remarkReceiveContract").attr("readonly","readonly");
	    		$("#timeReceiveContract").attr("readonly","readonly");
	    		$("#timeReceiveContract").removeAttr("onclick");
	    		$(".timeReceiveContractStatus").hide();
	    	} else if("timeContractFull" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('贷款合同齐全时间不能为空!',"#timeContractFull",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeContractFull = timeCValue;
	    		data.timeContractFullStatus = 20;
	    		data.timeCName = timeCName;
	    		data.remarkContractFull = $('#remarkContractFull').val();
	    		
	    		$("#remarkContractFull").attr("readonly","readonly");
	    		$("#timeContractFull").attr("readonly","readonly");
	    		$("#timeContractFull").removeAttr("onclick");
	    		$(".timeContractFullStatus").hide();
	    	} else if("timeContractHandPrint" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('合同移交机打时间不能为空!',"#timeContractHandPrint",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeContractHandPrint = timeCValue;
	    		data.timeContractHandPrintStatus = 20;
	    		data.timeCName = timeCName;
	    		data.remarkContractHandPrint = $('#remarkContractHandPrint').val();
	    		
	    		$('#remarkContractHandPrint').attr("readonly","readonly");
	    		$("#timeContractHandPrint").attr("readonly","readonly");
	    		$("#timeContractHandPrint").removeAttr("onclick");
	    		$(".timeContractHandPrintStatus").hide();
	    	} else if("timeSendToBank" == idAttr){
	    		if(timeCValue == ""){
	    			layer.tips('合同送交银行时间不能为空!',"#timeSendToBank",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		if($("#timeSendToBank2").val() == ""){
	    			layer.tips('请选择上下午!',"#timeSendToBank2",{tips: 4});
	    			saving = false;
	    			return;
	    		}
	    		data.timeSendToBank = timeCValue;
	    		data.timeSendToBankStatus = 20;
	    		data.timeSendToBank2 = $("#timeSendToBank2").val();
	    		data.timeCName = timeCName;
				data.remarkContractPrint = $('#remarkContractPrint').val();
	    		
	    		$('#remarkContractPrint').attr("readonly","readonly");
	    		$("#timeSendToBank").attr("readonly","readonly");
	    		$("#timeSendToBank").removeAttr("onclick");
	    		$("#timeSendToBank2").attr("disabled","disabled");
	    		$(".timeSendToBankStatus").hide();
	    	}
	    	$.dpAjax({
	    		data:data,
		    	url:'${basePath}/DzLoanMiddleAuditController/commitTime',
	   			success: function(datas){
	   				layer.msg('执行成功！', {icon: 6});
	   				$("#fkId").val(datas.result);
	   			},
	   			complete:function(){
	   				saving = false;
	   			}
	    	});
	    }
	    
    </script>
</body>
</html>
